/**
* @author Hyder
* @url http://youhack.me/2010/05/04/username-availability-check-in-registration-form-using-jqueryphp/
*/

$(document).ready(function() {
	$("#nev_username").change(function() { //if theres a change in the username textbox

		var username = $("#nev_username").val(); //Get the value in the username textbox
		if(username.length > 3) { //if the length greater than 3 characters
			$("#availability_status").html('<img src="templates/Vram/images/form_ajax_loader.gif" align="absmiddle">&nbsp;Checking availability...'); //Add a loading image in the span id="availability_status"

			$.ajax({  //Make the Ajax Request
				type: "POST",  
				url:  "remote/ajax.php",  //file name
				data: "sec=1&username="+ username,  //data
				success: function(server_response) {  
				   $("#availability_status").ajaxComplete(function(event, request){ 

						if(server_response == '0') { //if ajax_check_username.php return value "0"
							$("#availability_status").html('<img src="templates/Vram/images/small_tick.png" align="absmiddle"> <font color="Green"> Available </font>  ');
							//add this image to the span with id "availability_status"
						} else  if(server_response == '1') {  //if it returns "1"
							 $("#availability_status").html('<img src="templates/Vram/images/small_cross.png" align="absmiddle"> <font color="red">Not Available </font>');
						}
				   });
			   } 
		  }); 
		} else {
			$("#availability_status").html('<img src="templates/Vram/images/small_warning.png" align="absmiddle"> <font color="#cc0000">Username too short</font>');
			//if in case the username is less than or equal 3 characters only 
		}

		return false;
	});
});